import os.path
import sys
from datetime import datetime

from selenium import webdriver
from selenium.webdriver.edge.service import Service
from webdriver_manager.microsoft import EdgeChromiumDriverManager


Driver = webdriver.Edge(service=Service(EdgeChromiumDriverManager().install()))


def ScreenShot():
    # 1.把截图放在 screen_shot/年-月-日/ 文件夹下，
    dir = "../screen_shot/" + datetime.now().strftime("%Y-%m-%d")
    # 2.如果文件夹不存在则创建
    if not os.path.exists(dir):
        os.mkdir(dir)
    # 3.图片名：方法名-时-分-秒.png
    file_name = sys._getframe().f_back.f_code.co_name + \
                "-" + datetime.now().hour.__str__() + \
                "-" + datetime.now().minute.__str__() + \
                "-" + datetime.now().second.__str__() + ".png"
    # 4.保存截图：screen_shot/2025-02-20/20_29_40.png
    Driver.save_screenshot(dir + "/" + file_name)
